package com.example.doublepink.dialogautodismisstest;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

/**
 * Created by doublepink on 16/9/21.
 */
public class SimpleDialog extends Dialog{

    private Context mContext;
    private OnButtonClickListener onButtonClickListener;
    private Button mBtnCancel,mBtnEnsure;

    public SimpleDialog(Context context) {
        super(context);
        this.mContext = context;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_dialog_simple);
        initViewListener();
    }

    /**
     * 初始化组件监听器
     */
    private void initViewListener() {
        mBtnCancel = (Button) findViewById(R.id.cancel);
        mBtnEnsure = (Button) findViewById(R.id.ok);
        mBtnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (null != onButtonClickListener) {
                    onButtonClickListener.onNegativeButtonClick();
                }
            }
        });
        mBtnEnsure.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dismiss();
                if (null != onButtonClickListener) {
                    onButtonClickListener.onPositiveButtonClick();
                }
            }
        });
    }


    /**
     * 设置回调接口
     *
     * @param onButtonClickListener
     */
    public void setOnButtonClickListener(OnButtonClickListener onButtonClickListener) {
        this.onButtonClickListener = onButtonClickListener;
    }

    /**
     * 回调接口
     */
    public interface OnButtonClickListener {

        void onPositiveButtonClick();

        void onNegativeButtonClick();
    }

}
